package cfsmon.logic.dfm;

import java.io.OutputStream;

import org.apache.log4j.Logger;

import cfsmon.core.Backend;

public class DfmBackend implements Backend {

	private static Logger logger = Logger.getLogger(Backend.class);
	
	@Override
	public void compile(IDfm dfm, OutputStream out, int monitorSlots) throws Exception{
		
		if (dfm != null){
			dfm.setMaximumNumberOfMonitors(monitorSlots);
		}
		
		logger.info("Starting output optimization.");
		IDfm optDfm = DfmOptimizer.optimize(dfm);
		
		logger.info("Starting code generation.");
		String header = DfmToCHeaderTranslator.translate(optDfm);
		
		if (header != null){
			logger.info("Writing header.");
			out.write(header.getBytes());
		}
	}

}
